<?php
/**
 * Create By: PhpStorm
 * User: yihua
 * File: UserAddress.php
 * Date: 2017/1/5
 * Time: 23:22
 */

namespace app\api\model\page\user;

use app\library\PageBase;
use app\api\model\dao\UserAddress;
use app\library\Flag;
use app\library\Error;
use think\Validate;
use think\Log;

class SetDefaultAddress extends PageBase
{
    //private $tableUserAddress;
    private $objUserAddressModel;

    public function __construct()
    {
        parent::__construct();
        $this->objUserAddressModel = new UserAddress();
    }

    /**
     * @return array
     * @DESC �����û��ջ���ַ
     */
    public function excute($param)
    {

        if (empty($param['address_id']) || empty($param['user_id'])) {
            Log::alert(__METHOD__ . ' param: ' . json_encode($param));
            return $this->getRes(Error::ERR_PARAM);
        }
        $ret = $this->objUserAddressModel->setDefaultAddress($param['address_id'], $param['user_id']);
        if (false === $ret) {
            return $this->getRes(Error::ERR_SYS);
        }
        return $this->getRes();

    }


    /*
       public function removeUserAddress()
       {
       if (!isset($this->param['user_id']) || !isset($this->param['address_id'])) {
       return $this->getRes(Error::ERR_PARAM);
       }
       $res = $this->userAddressModel->removeAddress($this->param['user_id'],$this->param['address_id']);
       if ($res != 0) {
       return $this->getRes();
       } else {
       $this->data = $res;
       return $this->getRes(Error::ERR_USER_ADDRESS_REMOVE);
       }
       }


       public function updateUseraddress()
       {
       if (!isset($this->param['address_id'])) {
       return $this->getRes(Error::ERR_PARAM);
       }
       $res = $this->userAddressModel->updateAddress($this->param);
       if (false === $res) {
       return $this->getRes(Error::ERR_USER_ADDRES_UPDATE);
       } else {
       return $this->getRes();
       }
       }


       public function getUserAddress()
       {
    //return var_dump(Flag::SMS_EXPIRE_TIME);
    //return Common::createVerificationCode(18515030719,6,1);


    //Ĭ�ϲ�ѯ��Ч�ĵ�ַ
    //$this->data = Db::table($this->table_name)->where('status',1)->field('create_time,update_time',true)->select();
    if (!isset($this->param['user_id'])) {
    return $this->getRes(Error::ERR_PARAM);
    }
    $res = $this->userAddressModel->getAddressByUserid($this->param['user_id']);
    //var_dump($res);
    if (false === $res) {
    return $this->getRes(Error::ERR_SYS);
    } else {
    $this->data = $res;
    return $this->getRes();
    }
    }

    public function setDefaultAddress()
    {
    if (!isset($this->param['address_id']) || !isset($this->param['user_id'])) {
    Log::alert(__METHOD__ . ' param: ' . json_encode($this->param));
    return $this->getRes(Error::ERR_PARAM);
    }
    $ret = $this->userAddressModel->setDefaultAddress($this->param['address_id'], $this->param['user_id']);
    if(false === $ret){
    return $this->getRes(Error::ERR_SYS);
    }
    return $this->getRes();
    }



     */
}

